#define  _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
using namespace std;

int n, k, ret = -1, tmp;
vector<int> arr;

void dfs(int pos)
{
	if (tmp && tmp % k == 0)
	{
		ret = max(ret, tmp);
	}
	for (int i = pos; i < n; i++)
	{
		tmp += arr[i];
		dfs(i + 1);
		tmp -= arr[i];
	}
}
int main()
{
	cin >> n >> k;
	arr.resize(n);
	for (int i = 0; i < n; i++) cin >> arr[i];
	dfs(0);
	cout << ret << endl;
}